<?php
/**
 * 	Bushido
 *
 * @category   Bushido
 * @package    Bushido_Object
 * @copyright  Copyright (c) 2008-2009 Nathan Keyes
 * @author Nathan Keyes
 * @version    $Id: Object.php 7 2009-11-14 22:42:08Z nkeyes $
 */

class Bushido_Object implements Bushido_Acl_Resource_Interface
{
	
	/**
	 * 
	 * @param $name
	 * @return mixed
	 */
	public function &__get($name)
	{
		if(method_exists($this, "get" . ucfirst($name)))
		{
			$method = "get" . ucfirst($name);
			return $this->$method();
		}
		else
		{
			throw new Bushido_Object_Exception("Unknown property '$name' in class " . get_class($this));
		}
	}
	
	/**
	 * 
	 * @param $name
	 * @param $value
	 * @return void
	 */
	public function __set($name, $value)
	{
		if(method_exists($this, "set" . ucfirst($name)))
		{
			$method = "set" . ucfirst($name);
			return $this->$method($value);
		}
		else
		{
			throw new Bushido_Object_Exception("Unknown property '$name' in class '" . get_class($this) . "' or property is read-only");
		}
	}
	
	/**
	 * (non-PHPdoc)
	 * @see library/Zend/Acl/Resource/Zend_Acl_Resource_Interface#getResourceId()
	 */
	public function getResourceId()
	{
		return get_class($this);
	}
	
	/**
	 * (non-PHPdoc)
	 * @see library/Bushido/Acl/Resource/Bushido_Acl_Resource_Interface#setAccess()
	 */
	public function setAccess(Zend_Acl $acl)
	{
		if(!$acl->has($this->getResourceId()))
		{
			$acl->add(new Zend_Acl_Resource($this->getResourceId()));
			$acl->allow(Bushido_App::session()->appconfig->defaultRole, $this->getResourceId());
		}
		
	}
}
